package com.lzy.okgo.convert;

import com.google.gson.Gson;

import okhttp3.Response;

/**
 * ================================================
 * 作    者：jeasonlzy（廖子尧）Github地址：https://github.com/jeasonlzy0216
 * 版    本：1.0
 * 创建日期：16/9/11
 * 描    述：字符串的转换器
 * 修订历史：
 * ================================================
 */
public class ResultConvert<E> implements Converter<E> {

    private Class mclazz;
   /* public static ResultConvert create() {
        return ConvertHolder.convert;
    }*/

    public ResultConvert (Class calzz) {
        mclazz=calzz;

    }


   /* private static class ConvertHolder {
        private static ResultConvert convert = new ResultConvert();
    }*/

    @Override
    public E convertSuccess(Response value) throws Exception {
        String str = "[{'time':'kevin','value':'25'},{'time':'cissy','value':'24'}]";
        String str2="{\"time\":\"2016-11-13 20:35:00\",\"value\":\"116.298993,39.946159,276.0,0.5;116.305271,39.94388,276.0,0.5;116.310533,39.941556,276.0,0.5;116.350249,39.939835,299.0,0.3;116.355784,39.932646,315.0,0.2;116.355784,39.932646,315.0,0.2;116.354597,39.957945,300.0,0.3;116.347169,39.967694,297.0,0.4;116.340217,39.976391,295.0,0.4;\"}";
        str=value.body().string();
       /* Result<Entity> e1      = new Gson().fromJson(str, new TypeToken<Result<Entity>>() {
        }.getType());*/

//        ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
        E e2      = (E)new Gson().fromJson(str,mclazz);
       /* Type t= new TypeToken<Result<Entity>>() {
        }.getr;*/
/*
        Type type2 = ((ParameterizedType) t).getActualTypeArguments()[0];
         Entity  e=  new Gson().fromJson(str2,type2);*/

        E entity =(E) e2;
        return entity;
    }


}
